package com.huawei.springboot2023.business.user.controller;

import com.huawei.springboot2023.core.annotations.MySysLog;
import com.huawei.springboot2023.core.annotations.MySysLogOpration;
import com.huawei.springboot2023.core.dto.MyResult;
import com.huawei.springboot2023.core.util.MyRedisUtil;
import com.wf.captcha.GifCaptcha;
import com.wf.captcha.base.Captcha;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 模块名称：
 * 模块类型：
 * 编码人：周城阳
 * 编码时间：2023/3/17
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class ReqCodeController {

    @Autowired
    private MyRedisUtil redisUtil;

    @RequestMapping(value = "/reCode",method = RequestMethod.GET)
    @ResponseBody
    @MySysLog(modelName="验证码",methodDesc = "获取验证码",methodType = MySysLogOpration.GET)
    protected MyResult getReqCode(String localID)  {

        MyResult myResult = new MyResult();
        //创建验证码对象
        //1. 数学计算验证码(长px，宽px，长度)
        //ArithmeticCaptcha arithmeticCaptcha = new ArithmeticCaptcha(100, 42);
        GifCaptcha gifCaptcha = new GifCaptcha(100, 42, 5);

        gifCaptcha.setCharType(Captcha.TYPE_NUM_AND_UPPER);

        String text = gifCaptcha.text();// 计算的文字结果值
        System.out.println("验证码：【" + text + "】");



        redisUtil.set("reqCode#"+localID,text,60*10);
//        redisUtil.expire("reqCode#"+localId,60);


        myResult.setMsg("验证码获取成功");
        myResult.setData(gifCaptcha.toBase64());


        return myResult;
    }
}
